﻿using Microsoft.Extensions.DependencyInjection;
using TestProject1.DependencyInjection;
using UnitTest.iRepository;
using UnitTest.Model;

namespace TestProject1.Repository_Test;

public class StudentService_Should
{
    private IRepository<Student> _studentRepository;
    DI_Test _diTest = new DI_Test();

    public StudentService_Should()
    {

        var container = _diTest.DICollections();
        _studentRepository = container.Services.GetService<IStudentRepository>();
    }
    
    [Fact]
    public void StudentServices_Test()
    {
        Assert.NotNull(_studentRepository);
    }


    [Fact]
    public async void Get_Student_Test()
    {
        var data = await _studentRepository.GetList();

        Assert.True(data.Any());
    }

    [Fact]
    public async void Add_Student_Test()
    {
        Student student = new Student()
        {
            ID = 8,
            Name = "测试2",
            Age = 22,
            Gender = "女",
            Status =1

        };

        var BId = await _studentRepository.Add(student);

        Assert.True(BId > 0);
    }

    
    //TODO 有问题
    [Fact]
    public async void Delete_Blog_Test()
    {
        Student student = new Student()
        {
            ID = 6,
            Name = "测试2",
            Age = 22,
            Gender = "女",
            Status =1
        };
        var IsDel = await _studentRepository.Delete(student);

        Assert.True(IsDel>0);
    }
}